package cg.project.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
/**
 *
 * @author BWHB
 * @date 2024/11/19 19:05
 * @param

 */

@Component// 普通的类交给spring容器管理的
public class EmailUtil {
        //负责发送数据到邮箱服务器
        @Autowired
        private JavaMailSender mailSender;

        public void send(String loginEmail,String randomCode){

                //1. 创建一个封装邮箱信息的对象
                SimpleMailMessage msg = new SimpleMailMessage();
                //email-info
                msg.setFrom("1441439903@qq.com");//发送方邮箱需要和application-dev.yml中配置的邮箱保持一致
                msg.setSubject("常工院登录验证码");//邮箱的主题

                msg.setText(randomCode);

                msg.setTo(loginEmail);//邮箱的接收方
                //end - 发送邮箱
                mailSender.send(msg);
        }
}

